//
//  GFDramViewController.m
//  GoodFood
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 荣伟峰. All rights reserved.
//

#import "GFDramViewController.h"

@interface GFDramViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSArray *imageArr;
@property (nonatomic, retain) NSArray *titleArr;

@end

@implementation GFDramViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView.allowsSelection = YES;
    
}

- (void)creatBlurView {
    
    UIImageView *blurImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    blurImageView.image = [UIImage imageNamed:@"haizei2.jpg"];
    [self.view addSubview:blurImageView];
    blurImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualView = [[UIVisualEffectView alloc] initWithEffect:blur];
    visualView.frame = blurImageView.frame;
    visualView.alpha = 1;
    [blurImageView addSubview:visualView];
}

- (void)creatTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, ScreenWidth / 375 * 40, ScreenWidth, ScreenHeight - ScreenWidth / 375 * 40) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
    
}

#pragma mark - tableViewDataSource协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else if (section == 1) {
        return 6;
    } else {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    
    cell.backgroundColor = [UIColor clearColor];
    
    if (indexPath.section == 0) {
        cell.textLabel.text = self.titleArr[0];
        cell.imageView.image = [UIImage imageNamed:self.imageArr[0]];
    } else if (indexPath.section == 1) {
        cell.textLabel.text = self.titleArr[indexPath.row + 1];
        cell.imageView.image = [UIImage imageNamed:self.imageArr[indexPath.row + 1]];
    } else {
        cell.textLabel.text = self.titleArr[7];
        cell.imageView.image = [UIImage imageNamed:self.imageArr[7]];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.textColor = [UIColor whiteColor];
    
    return cell;
}

/* 分区数 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    if (section == 1) {
        
        UIView *headView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth / 375 * 70)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 375 * 10, ScreenWidth / 375 * 30, ScreenWidth / 375 * 100, ScreenWidth / 375 * 30)];
        label.text = @"食物分类";
        label.textColor = [UIColor lightGrayColor];
        [headView1 addSubview:label];
        
        return headView1;
    } else {
        
        UIView *headView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth / 375 * 70)];
        return headView2;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else {
        return ScreenWidth / 375.0 * 70;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ScreenWidth / 375.0 * 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    NSArray *arr = @[@"group", @"cooking", @"brand", @"restaurant", @"season", @"near"];
    
    YRSideViewController *con = (YRSideViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    
    if (indexPath.section == 1) {
        if (5 == indexPath.row) {
            GFNearHomeViewController *homeVc = [[GFNearHomeViewController alloc] init];
            [con hideSideViewController:YES];
            
            [(UINavigationController *)con.rootViewController pushViewController:homeVc animated:YES];

        } else {
            GFClassifyViewController *classifyVC = [[GFClassifyViewController alloc] init];
            
            classifyVC.needUrlStr = [arr objectAtIndex:indexPath.row];
            //
            classifyVC.titleName = [self.titleArr objectAtIndex:indexPath.row + 1];
            
            
            [con hideSideViewController:YES];
            
            [(UINavigationController *)con.rootViewController pushViewController:classifyVC animated:YES];

        }
        

        self.tableView.allowsSelection = NO;
        
    } else if (indexPath.section == 2) {
        
        GFMoreMessageViewController *moreVC = [[GFMoreMessageViewController alloc] init];
        
        [con hideSideViewController:YES];
        
        [(UINavigationController *)con.rootViewController pushViewController:moreVC animated:YES];
        
        self.tableView.allowsSelection = NO;
        
    } else {
        
//
        GFCityListViewController *cityListVC = [[GFCityListViewController alloc] init];
        [con hideSideViewController:YES];
        
        [(UINavigationController *)con.rootViewController pushViewController:cityListVC animated:YES];
        
        self.tableView.allowsSelection = NO;
        
        
        
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatBlurView];
    [self creatTableView];
//    if (self.isnight == YES) {
        self.titleArr = @[@"切换城市", @"类别", @"烹饪方式", @"品牌", @"连锁餐饮", @"季节", @"附近", @"更多"];
        
        self.imageArr = @[@"iconfont-chengshidingwei", @"leibie", @"pengrenfangshi", @"pinpai", @"liansuocanyin", @"jijie", @"fujin", @"dian"];


    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
